package org.sasha.roulette.actionbar;

import java.util.Date;

import javax.inject.Inject;

import org.sasha.roulette.data.DBHelper;
import org.sasha.roulette.data.Spin;
import org.sasha.roulette.event.SpinRegisteredEvent;

import com.github.peholmst.mvp4vaadin.Presenter;
import com.google.common.eventbus.EventBus;

@SuppressWarnings("serial")
public class FastSpinCreationPresenter extends Presenter<FastSpinCreationView>{

    private final EventBus evenBus;
    
    private DBHelper helper;
    
    @Inject
    public FastSpinCreationPresenter(final DBHelper helper, final EventBus eventBus) {
        super();
        this.evenBus = eventBus;
        this.helper = helper;
    }
    
    public void addSpin(int value) {
        final Spin spin = new Spin();
        spin.setValue(value);
        spin.setTimestamp(new Date());
        helper.saveSpin(spin);
        evenBus.post(new SpinRegisteredEvent(spin));
    }

}
